<?php
namespace app\index\controller;

use think\Controller;
use think\Config;
use think\Request;
use app\index\model\User;

class Users extends Controller{
    public function teacher(){
        $Model = new User();
        $teacherlist = $Model->teacher();
        // dump($teacherlist->toArray());
        $this->assign('list',$teacherlist);
        return $this->fetch();
    }

    public function student(){
        $Model = new User();
        $studentlist = $Model->student();
        // dump($teacherlist->toArray());
        $this->assign('list',$studentlist);
        return $this->fetch();
    }

    //状态变更
    public function setStatus(){                  //从前端的jQuery调用控制器
        Config::set("default_return_type","json");//设置返回的类型为json类型

        $requset = Request::instance();           //拿到前端的传入数据
        if($requset->isAjax()){                   //判断数据是否通过ajax传过来
            $status = $requset->post("status");
            $ids = $requset->post("ids");
            $userModel = new User();
            $res = $userModel->setStatus($status,$ids);
            if($res === false){
                return array("flag"=>0,"msg"=>"更改状态失败");
            }
            return array("flag"=>1,"msg"=>"成功");
        }else{
            return array("flag"=>0,"msg"=>"非Ajax访问");
        }
       
    }
}

?>